package com.example.myapplication;

import android.content.pm.ApplicationInfo;

/**
 * 应用使用统计数据模型
 */
public class AppUsageInfo {
    private String packageName;
    private String appName;
    private String appIcon; // 应用图标路径或资源ID
    private long totalTimeInForeground; // 总前台时间（毫秒）
    private long lastTimeUsed; // 最后使用时间
    private int launchCount; // 启动次数
    private ApplicationInfo applicationInfo; // 应用信息对象

    public AppUsageInfo() {
    }

    public AppUsageInfo(String packageName, String appName, long totalTimeInForeground) {
        this.packageName = packageName;
        this.appName = appName;
        this.totalTimeInForeground = totalTimeInForeground;
    }

    // Getters and Setters
    public String getPackageName() {
        return packageName;
    }

    public void setPackageName(String packageName) {
        this.packageName = packageName;
    }

    public String getAppName() {
        return appName;
    }

    public void setAppName(String appName) {
        this.appName = appName;
    }

    public String getAppIcon() {
        return appIcon;
    }

    public void setAppIcon(String appIcon) {
        this.appIcon = appIcon;
    }

    public long getTotalTimeInForeground() {
        return totalTimeInForeground;
    }

    public void setTotalTimeInForeground(long totalTimeInForeground) {
        this.totalTimeInForeground = totalTimeInForeground;
    }

    public long getLastTimeUsed() {
        return lastTimeUsed;
    }

    public void setLastTimeUsed(long lastTimeUsed) {
        this.lastTimeUsed = lastTimeUsed;
    }

    public int getLaunchCount() {
        return launchCount;
    }

    public void setLaunchCount(int launchCount) {
        this.launchCount = launchCount;
    }


    public ApplicationInfo getApplicationInfo() {
        return applicationInfo;
    }

    public void setApplicationInfo(ApplicationInfo applicationInfo) {
        this.applicationInfo = applicationInfo;
    }

    /**
     * 格式化使用时间显示
     */
    public String getFormattedTime() {
        long totalSeconds = totalTimeInForeground / 1000;
        long hours = totalSeconds / 3600;
        long minutes = (totalSeconds % 3600) / 60;
        long seconds = totalSeconds % 60;

        if (hours > 0) {
            return String.format("%d小时%d分钟", hours, minutes);
        } else if (minutes > 0) {
            return String.format("%d分钟", minutes);
        } else {
            return String.format("%d秒", seconds);
        }
    }

    /**
     * 获取使用时间百分比（相对于总时间）
     */
    public float getUsagePercentage(long totalUsageTime) {
        if (totalUsageTime == 0) return 0;
        return (float) totalTimeInForeground / totalUsageTime * 100;
    }
}
